<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.14.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>DM-CtrlH7-BF-DevProgram: bsp_dwt</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script type="text/javascript" src="clipboard.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript" src="cookie.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectlogo"><img alt="Logo" src="DMBF-Black.png"/></td>
  <td id="projectalign">
   <div id="projectname">DM-CtrlH7-BF-DevProgram<span id="projectnumber">&#160;beta 0.1</span>
   </div>
   <div id="projectbrief">C.ONE Studio Damiao Development Board Framework</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.14.0 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search/",'.html');
</script>
<script type="text/javascript">
$(function() { codefold.init(); });
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search',true);
  $(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(function(){initNavTree('md_bsp_2dwt_2bsp__dwt.html','',''); });
</script>
<div id="container">
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>

<div><div class="header">
  <div class="headertitle"><div class="title">bsp_dwt </div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p><a class="anchor" id="autotoc_md8"></a></p>
<p>DWT是stm32内部的一个"隐藏资源",他的用途是给下载器提供准确的定时,从而为调试信息加上时间戳.并在固定的时间间隔将调试数据发送到你的xxlink上.</p>
<h1 class="doxsection"><a class="anchor" id="autotoc_md9"></a>
常用功能</h1>
<h2 class="doxsection"><a class="anchor" id="autotoc_md10"></a>
计算两次进入同一个函数的时间间隔</h2>
<div class="fragment"><div class="line"><span class="keyword">static</span> uint32_t cnt;</div>
<div class="line"><span class="keywordtype">float</span> deltaT;</div>
<div class="line"> </div>
<div class="line">deltaT=<a class="code hl_function" href="bsp__dwt_8c.html#af3972f1a5023286afdabf8e79abc5ed7">DWT_GetDeltaT</a>(&amp;cnt);</div>
<div class="ttc" id="absp__dwt_8c_html_af3972f1a5023286afdabf8e79abc5ed7"><div class="ttname"><a href="bsp__dwt_8c.html#af3972f1a5023286afdabf8e79abc5ed7">DWT_GetDeltaT</a></div><div class="ttdeci">float DWT_GetDeltaT(uint32_t *cnt_last)</div><div class="ttdoc">获取两次调用之间的时间间隔,单位为秒/s</div><div class="ttdef"><b>Definition</b> bsp_dwt.c:62</div></div>
</div><!-- fragment --><h2 class="doxsection"><a class="anchor" id="autotoc_md11"></a>
计算执行某部分代码的耗时</h2>
<div class="fragment"><div class="line"><span class="keywordtype">float</span> start,end;</div>
<div class="line">start=DWT_DetTimeline_ms();</div>
<div class="line"> </div>
<div class="line"><span class="comment">// some proc to go... </span></div>
<div class="line"><span class="keywordflow">for</span>(uint8_t i=0;i&lt;10;i++)</div>
<div class="line"> foo();</div>
<div class="line"> </div>
<div class="line">end = DWT_DetTimeline_ms()-start;</div>
</div><!-- fragment --><p>我们还提供了一个宏用于调试计时:</p>
<div class="fragment"><div class="line"><span class="preprocessor">#define TIME_ELAPSE(dt, code)                    \</span></div>
<div class="line"><span class="preprocessor">    do                                           \</span></div>
<div class="line"><span class="preprocessor">    {                                            \</span></div>
<div class="line"><span class="preprocessor">        float tstart = DWT_GetTimeline_s();      \</span></div>
<div class="line"><span class="preprocessor">        code;                                    \</span></div>
<div class="line"><span class="preprocessor">        dt = DWT_GetTimeline_s() - tstart;       \</span></div>
<div class="line"><span class="preprocessor">        LOGINFO(&quot;[DWT] &quot; #dt &quot; = %f s\r\n&quot;, dt); \</span></div>
<div class="line"><span class="preprocessor">    } while (0)</span></div>
</div><!-- fragment --><p>传入一个float类型的变量,并将你要执行的代码写入第二个参数:</p>
<div class="fragment"><div class="line"><span class="keyword">static</span> <span class="keywordtype">float</span> my_func_dt;</div>
<div class="line"><a class="code hl_define" href="bsp__dwt_8h.html#a9b46a15916bbafb8610eb121c36dce04">TIME_ELAPSE</a>(my_func_dt,</div>
<div class="line">            Function1(vara);</div>
<div class="line">            Function2(some, var);</div>
<div class="line">            Function3(your,param);</div>
<div class="line">             <span class="comment">// something more</span></div>
<div class="line">             );</div>
<div class="line"><span class="comment">// my_func_dt can be used for other purpose then;</span></div>
<div class="ttc" id="absp__dwt_8h_html_a9b46a15916bbafb8610eb121c36dce04"><div class="ttname"><a href="bsp__dwt_8h.html#a9b46a15916bbafb8610eb121c36dce04">TIME_ELAPSE</a></div><div class="ttdeci">#define TIME_ELAPSE(dt, code)</div><div class="ttdoc">该宏用于计算代码段执行时间,单位为秒/s,返回值为float类型 首先需要创建一个float类型的变量,用于存储时间间隔 计算得到的时间间隔同时还会通过RTT打印到日志终端,...</div><div class="ttdef"><b>Definition</b> bsp_dwt.h:33</div></div>
</div><!-- fragment --> </div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
<div id="page-nav" class="page-nav-panel">
<div id="page-nav-resize-handle"></div>
<div id="page-nav-tree">
<div id="page-nav-contents">
</div><!-- page-nav-contents -->
</div><!-- page-nav-tree -->
</div><!-- page-nav -->
</div><!-- container -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.14.0 </li>
  </ul>
</div>
</body>
</html>
